import scrapy

from yueshushu.items import YueshushuItem


from scrapy_redis.spiders import RedisSpider

class ExampleSpider(RedisSpider):
    name = 'example'
    # 允许域名
    allowed_domains = ["exercise.kingname.info"]
    redis_key = 'example:start_urls'
    def parse(self, response):
        # pass
        print(response.body.decode())
        personList = response.xpath('/html/body/div/table/tbody/tr')
        for person in personList:
            item = YueshushuItem()
            person_info = person.xpath('td/text()').extract()
            item['name'] = person_info[0]
            item['age'] = person_info[1]
            item['salary'] = person_info[2]
            item['phone'] = person_info[3]
            yield item

'''
class ExampleSpider(scrapy.Spider):
    # 爬虫名称
    name = "example"
    # 允许域名
    allowed_domains = ["exercise.kingname.info"]
    # 爬虫地址
    start_urls = ["https://exercise.kingname.info/exercise_xpath_3.html"]

    def parse(self, response):
        print(response.body.decode())
        personList = response.xpath('/html/body/div/table/tbody/tr')
        for person in personList:
            item = YueshushuItem()
            person_info = person.xpath('td/text()').extract()
            item['name'] = person_info[0]
            item['age'] = person_info[1]
            item['salary'] = person_info[2]
            item['phone'] = person_info[3]
            yield item

'''